home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlibs.zip / INDEX.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  1KB  |  66 lines

  1. ;       Static Name Aliases
  2. ;
  3.         TITLE   index
  4. ;       NAME    index.C
  5.  
  6. ;  int  index(src, obj)
  7. ;       char *src;
  8. ;       char obj;
  9. ;
  10. ;  Returns the integer offset of character obj within string src.
  11. ;  Returns -1 if obj is not found within src.
  12. ;
  13. ;  index(src, '\0') is equivalent to strlen(src)
  14. ;
  15.  
  16.         .287
  17. _TEXT   SEGMENT  BYTE PUBLIC 'CODE'
  18. _TEXT   ENDS
  19. _DATA   SEGMENT  WORD PUBLIC 'DATA'
  20. _DATA   ENDS
  21. CONST   SEGMENT  WORD PUBLIC 'CONST'
  22. CONST   ENDS
  23. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  24. _BSS    ENDS
  25. DGROUP  GROUP   CONST,  _BSS,   _DATA
  26.         ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  27. _TEXT      SEGMENT
  28.         PUBLIC  _index
  29. _index  PROC NEAR
  30.         push    bp
  31.         mov     bp,sp
  32.         push    di
  33.         push    si
  34.         mov     si,[bp+4]       ;s
  35.         mov     di,si
  36. ; Line 6
  37. ;       s = 4
  38. ;       register si = s
  39. ;       c = 6
  40.  
  41.         mov     bl,[bp+6]       ;c
  42. $cmp:
  43.         lodsb
  44.         cmp     al,bl
  45.         je      cleanup
  46.         cmp     al,0
  47.         je      $nofind
  48.         jmp     $cmp
  49. $nofind:
  50.         xor     ax,ax
  51.         jmp     short out
  52. cleanup:
  53.         xchg    ax,si
  54.         sub     ax,di
  55. out:
  56.         dec     ax
  57.         pop     si
  58.         pop     di
  59.         mov     sp,bp
  60.         pop     bp
  61.         ret
  62.  
  63. _index  ENDP
  64. _TEXT   ENDS
  65. END
  66.